package com.ruge.core.tool;

import com.ruge.core.enums.SmsEnum;
import com.ruge.tool.date.DateTool;

import java.util.Date;

/**
 * @program: ruge-cloud
 * @description:
 * @author: ruge.wu
 * @create: 2022-01-09 00:52
 **/
public class RedisKeyTool {
    /**
     * 构造签到的key
     *
     * @param aid      当前用户id
     * @param signDate 签到日期
     * @return redis签到的key
     */
    public static String buildSignKey(Long aid, Date signDate) {
        return String.format("user:sign:%d:%s", aid, DateTool.getDateInstance(signDate, "yyyyMM"));
    }

    /**
     * 构造验证码的key
     *
     * @param smsEnum 验证码类型
     * @param phone   电话号
     * @return 验证码的key
     */
    public static String buildSmsKey(SmsEnum smsEnum, String phone) {
        return String.format("sms:%s:%s", smsEnum.getCode(), phone);
    }

    /**
     * @param blogId 文章id
     * @return redis微博的key
     */
    public static String buildBlogKey(Long blogId) {
        return String.format("blog:like:%d", blogId);
    }

    /**
     * 构建我的关注的key
     *
     * @param aid 博主id
     * @return redis微博的key
     */
    public static String buildFollowKey(Long aid) {
        return String.format("blog:follow:%d", aid);
    }

    /**
     * 构建我的粉丝的key
     *
     * @param aid 用户id
     * @return 构建后的key
     */
    public static String buildFansKey(Long aid) {
        return String.format("blog:fans:%d", aid);
    }

    /**
     * 构建我的粉丝feed的key
     *
     * @param aid 用户id
     * @return 构建后的key
     */
    public static String buildFansFeedKey(Long aid) {
        return String.format("blog:fansFeed:%d", aid);
    }

    /**
     * 构建秒杀优惠券的key
     *
     * @param couponId 优惠券id
     * @return 构建后key
     */
    public static String buildSecKillKey(String couponId) {
        return String.format("seckill:couponId:%s", couponId);
    }

    /**
     * 构建单人秒杀的key
     *
     * @param couponId 优惠券id
     * @param aid      用户id
     * @return 构建后的key
     */
    public static String buildSingleSecKillKey(String couponId, Long aid) {
        return String.format("seckill:single:couponId:%s:%d", couponId, aid);
    }

    /**
     * 构建积分排行榜的key
     *
     * @return 构建后key
     */
    public static String buildIntegralKey() {
        return String.format("aid:integral");
    }

    /**
     * 构建地理位置的key
     *
     * @return 构建后key
     */
    public static String buildLocationKey() {
        return String.format("aid:location");
    }
}
